stage.set_background("moon")
sprite = codesters.Sprite("alien1")
sprite.go_to(-175, -150)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
instructions = codesters.Text("Click on the sprite to shoot the basketball. Hit the basket to score a point!")
instructions.go_to(0, 50)
instructions.set_color("white")
stage.set_gravity(10)
sprite.set_gravity_off()
def click(sprite):
ball = codesters.Sprite("basketball")
ball.go_to(-175, -125)
ball.set_x_speed(10)
ball.set_y_speed(10)
# add other actions...
sprite.event_click(click)
stage.disable_right_wall()
def collision(net, hit_sprite):
my_var = hit_sprite.get_image_name()
if my_var == "basketball":
sprite.say("Score!")
hit_sprite.hide()
# add any other actions...
net.event_collision(collision)
score = 0
t = codesters.Teacher()
try:
tval1 = t.find_function('Display')[0][1]
tval3 = t.get_indent_at_line(t.find_function('Display')[0][0])
except:
tval1 = "DNE"
tval3 = "DNE"
try:
tval2 = t.get_parameters_for_function("Display")[0][0]
except:
tval2 = "DNE"
t1 = TestObjective()
t1.add_success("my_display" in tval1, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add in a Variable Display?")
t1.add_failure("my_display" not in tval1, "Oops! Did you change the name of the display?")
t2 = TestObjective()
t2.add_success(tval2 == "score", "Great job!")
t2.add_failure(tval2 != "score", "Did you change the variable to be displayed to score?")
t2.add_failure(tval2 == "DNE", "Did you add in a Variable Display?")
t3 = TestObjective()
t3.add_success(tval3 == 0, "Great job!")
t3.add_failure(tval3 > 0, 'Oops! Did you indent your display too many times?')
t3.add_failure(tval3 == "DNE", 'Did you drag in Variable Display?')
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)